<?php
/**
 * CreateTime: 2023/1/9 15:29
 */

namespace App\Func;

use App\Consts\BaseConsts\BaseConsts;

class MeDataFunc
{
    /**
     * 设置默认值
     * @param $data
     * @return mixed
     */
    public static function setDefault($data){
        $data['status'] = BaseConsts::STATUS_NORMAL;
        $data['owner_id'] = TokenFuc::getCurrentStaffInfo()['staff_id'];
        return $data;
    }

    public static function getUserInfoByIdCard(string $idCard){
        $provincialCode = mb_substr($idCard,0,2);
        $provincial = self::getProvincialConf($provincialCode);
        $birth = date("Y年m月d日",strtotime(mb_substr($idCard,6,8)));
        $gender = ($idCard[16] % 2) ? "男" : "女";
        return [
            'provincial' => $provincial,
            'birth' => $birth,
            'gender' => $gender,
        ];
    }

    private static function getProvincialConf(string $code){
        switch ($code[0]){
            case "1":
                switch ($code[1]){
                    case "1":
                        return "北京";
                    case "2":
                        return "天津";
                    case "3":
                        return "河北";
                    case "4":
                        return "山西";
                    case "5":
                        return "内蒙古";
                    default:
                        die("身份证获取错误");
                }
            case "2":
                switch ($code[1]){
                    case "1":
                        return "辽宁";
                    case "2":
                        return "吉林";
                    case "3":
                        return "黑龙江";
                    default:
                        die("身份证获取错误");
                }
            case "3":
                switch ($code[1]){
                    case "1":
                        return "上海";
                    case "2":
                        return "江苏";
                    case "3":
                        return "浙江";
                    case "4":
                        return "安徽";
                    case "5":
                        return "福建";
                    case "6":
                        return "江西";
                    case "7":
                        return "山东";
                    default:
                        die("身份证获取错误");
                }
            case "4":
                switch ($code[1]){
                    case "1":
                        return "河南";
                    case "2":
                        return "湖北";
                    case "3":
                        return "湖南";
                    case "4":
                        return "广东";
                    case "5":
                        return "广西";
                    case "6":
                        return "海南";
                    default:
                        die("身份证获取错误");
                }
            case "5":
                switch ($code[1]){
                    case "0":
                        return "重庆";
                    case "1":
                        return "四川";
                    case "2":
                        return "贵州";
                    case "3":
                        return "云南";
                    case "4":
                        return "西藏";
                    default:
                        die("身份证获取错误");
                }
            case "6":
                switch ($code[1]){
                    case "1":
                        return "陕西";
                    case "2":
                        return "甘肃";
                    case "3":
                        return "青海";
                    case "4":
                        return "宁夏";
                    case "5":
                        return "新疆";
                    default:
                        die("身份证获取错误");
                }
            case "7":
                switch ($code[1]){
                    case "1":
                        return "台湾";
                    default:
                        die("身份证获取错误");
                }
            case "8":
                switch ($code[1]) {
                    case "1":
                        return "香港";
                    case "2":
                        return "澳门";
                    default:
                        die("身份证获取错误");
                }
            default:
                die("省份获取失败");
        }
    }



}